﻿using FluentNHibernate.Mapping;

namespace TaskKernel.Domain.Nhibernate.Mappings
{
    public class DepartmentMap : ClassMap<Department>
    {
        public DepartmentMap()
        {
            Table("task_Departments");
            Id(x => x.UID, "GID").GeneratedBy.GuidNative();
            Map(x => x.WebPath, "WebPath");
            Map(x => x.DepartmentName, "DepartmentName");
            Map(x => x.MailBox, "DepartmentMail");
            Map(x => x.IsClaim, "IsClaim");
            Map(x => x.IsClaimNotify, "IsClaimNotify");
            Map(x => x.RatingRequired, "RatingRequired");
            HasMany(x => x.Tasks)
                .KeyColumns.Add("DepartmentGID")
                .Inverse()
                .Cascade.All().LazyLoad()
                .AsBag().Access.ReadOnlyPropertyThroughCamelCaseField();
            HasMany(x => x.UsersWithRole)
                .KeyColumns.Add("DepartmentGID")
                .Inverse()
                .Cascade.AllDeleteOrphan().LazyLoad()
                .AsSet().Access.ReadOnlyPropertyThroughCamelCaseField();
        }
    }
}